package com.wondersgroup.robot.dao;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;

import com.wondersgroup.robot.po.UserFavorites;

/**
 * Data access object (DAO) for domain model class UserFavorites.
 * 
 * @see com.wondersgroup.robot.po.UserFavorites
 * @author MyEclipse Persistence Tools
 */

public class UserFavoritesDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory.getLog(UserFavoritesDAO.class);

	// property constants
	public static final String LOG_NAME = "logName";

	public static final String UFL_ID = "uflId";

	public static final String USFA_NUM = "usfaNum";

	public void save(UserFavorites transientInstance) {
		log.debug("saving UserFavorites instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(UserFavorites persistentInstance) {
		log.debug("deleting UserFavorites instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public UserFavorites findById(java.lang.String id) {
		log.debug("getting UserFavorites instance with id: " + id);
		try {
			UserFavorites instance = (UserFavorites) getSession().get(
					"com.wondersgroup.robot.po.UserFavorites", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(UserFavorites instance) {
		log.debug("finding UserFavorites instance by example");
		try {
			List results = getSession().createCriteria(
					"com.wondersgroup.robot.po.UserFavorites").add(
					Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding UserFavorites instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from UserFavorites as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByLogName(Object logName) {
		return findByProperty(LOG_NAME, logName);
	}

	public List findByUflId(Object uflId) {
		return findByProperty(UFL_ID, uflId);
	}

	public List findByUsfaNum(Object usfaNum) {
		return findByProperty(USFA_NUM, usfaNum);
	}

	public List findAll() {
		log.debug("finding all UserFavorites instances");
		try {
			String queryString = "from UserFavorites";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public UserFavorites merge(UserFavorites detachedInstance) {
		log.debug("merging UserFavorites instance");
		try {
			UserFavorites result = (UserFavorites) getSession().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(UserFavorites instance) {
		log.debug("attaching dirty UserFavorites instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(UserFavorites instance) {
		log.debug("attaching clean UserFavorites instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}